package com.xukktest.demo.dao;

import com.xukktest.demo.domain.City;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.springframework.data.hadoop.hbase.RowMapper;

public class CityRowMapper implements RowMapper<City> {

    private static byte[] NAME = "name".getBytes();
    private static byte[] AGE = "age".getBytes();

    @Override
    public City mapRow(Result result, int rowNum) throws Exception {
        if(result.isEmpty()) return null;
        String name = Bytes.toString(result.getValue( NAME,"people".getBytes()));
        byte[] a=result.getValue( AGE,"age".getBytes());
        int age=0;
        if(a!=null){
            age= Bytes.toInt(a);
        }
        City dto = new City();
        dto.setCityName(name);
        dto.setAge(age);
        return dto;
    }
}
